/*
 * ikakeibo 0.6.0
 * Copyright (C)2009 wateray and contributors
 * wateray@gmail.com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

package com.wateray.ipassbook.ui.view.navigator;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JCheckBox;
import javax.swing.JPanel;

import com.wateray.ipassbook.ui.action.ActionManager;
import com.wateray.ipassbook.ui.action.ShowPassbookPageAction;
import com.wateray.ipassbook.ui.action.ShowReceiptAction;
import com.wateray.ipassbook.ui.action.ShowSubjectPageAction;
import com.wateray.ipassbook.ui.action.ShowTransferPageAction;
import com.wateray.ipassbook.ui.widget.CurtainPane;
import com.wateray.ipassbook.util.ImageManager;
import com.wateray.ipassbook.util.LanguageLoader;

/**
 * @author wateray
 * @create 2009-5-2
 */
public class CurtainPaneNavigator{

	public static CurtainPaneNavigator thisNavigator;
	private JPanel cutainPane;
	
	private CurtainPaneNavigator(){};
	
	public static CurtainPaneNavigator getInstance(){
		if(thisNavigator == null){
			thisNavigator = new CurtainPaneNavigator();
		}
		return thisNavigator;
	}
	
	public JPanel getCurtainPanelView() {
		if (cutainPane == null) {
			cutainPane = new JPanel(new BorderLayout());
			CurtainPane cp = getCurtainPane();
			cp.setAnimated(true);
			
			//show the first layer. 
			cp.setSelectedPane(0);
			cutainPane.add(cp, BorderLayout.CENTER);

			JCheckBox box = getAnimationCheckBox(cp);
			cutainPane.add(box, BorderLayout.SOUTH);
		}

		return cutainPane;
	}
	
	private CurtainPane getCurtainPane() {
		CurtainPane fp = new CurtainPane();
		fp.setAnimated(true);
		fp.addPane(LanguageLoader.getString("Keep_Accounts"), ImageManager.getImageIconByShortName("application_edit.png"),
				getFileFolderPane());
		fp.addPane(LanguageLoader.getString("Configuration"), ImageManager.getImageIconByShortName("applications-system.png"), getDetailsPane());
		fp.addPane(LanguageLoader.getString("Others"), ImageManager.getImageIconByShortName("other.gif"), getOtherPlacePane());
		return fp;
	}
	
	private ListPane getDetailsPane() {
		ListPane p = new ListPane();
		p.addItem(LanguageLoader.getString("Subject"), ImageManager.getImageIconByShortName("task.gif"),ActionManager.getAction(ShowSubjectPageAction.class));
		p.setSize(185, 74);
		return p;
	}

	private ListPane getOtherPlacePane() {
		ListPane p = new ListPane();
		p.addItem("System (C:)",ImageManager.getImageIconByShortName("drive.png"));
		p.setSize(185, 117);
		return p;
	}

	private ListPane getFileFolderPane() {
		ListPane p = new ListPane();
		p.addItem(LanguageLoader.getString("Receipt"), ImageManager.getImageIconByShortName("table_go.png"),ActionManager.getAction(ShowReceiptAction.class));
		p.addItem(LanguageLoader.getString("TransferPage"), ImageManager.getImageIconByShortName("table_go.png"),ActionManager.getAction(ShowTransferPageAction.class));
		p.addItem(LanguageLoader.getString("PassbookPage"), ImageManager.getImageIconByShortName("table_go.png"),ActionManager.getAction(ShowPassbookPageAction.class));
		p.setSize(185, 86);
		return p;
	}
	
	private JCheckBox getAnimationCheckBox(final CurtainPane cp) {
		final JCheckBox box = new JCheckBox("Enable Animation");
		box.setSelected(true);
		box.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				cp.setAnimated(box.isSelected());
			}
		});
		return box;
	}
	
}
